<template>
	<view>
		<view class="u-flex user-box u-p-l-30 u-p-r-20 u-p-b-30">
			<view class="u-m-r-10">
				<ossUploadPic></ossUploadPic>
				<!-- <u-avatar :src="pic" size="80"></u-avatar> -->
			</view>
			<view class="u-flex-1">
				<view class="u-font-18 u-p-b-20">{{name}}</view>
				<view class="u-font-14 u-tips-color">信箱:{{email}}</view>
			</view>

		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell icon="setting" isLink url="./baseinfo" title="个人信息"></u-cell>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell icon="rmb-circle" title="我的订单"></u-cell>
				<u-cell icon="star" isLink url="./collect" title="商品收藏"></u-cell>
				<u-cell icon="map" title="收货地址" isLink url="/pages/cart/address"></u-cell>
			</u-cell-group>
		</view>

		<view class="u-m-t-20">
			<u-cell-group>
				<u-cell icon="reload" title="注销" :isLink="true" @tap='logout'></u-cell>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	let access_token;
	export default {
		data() {
			return {
				pic: '',
				name: '’'/* getApp().globalData.mqc */,
				email:''
			}
		},
		onLoad() {			
			access_token = uni.getStorageSync('access_token');
			//this.name = getApp().globalData.mqc;
			//console.log(getApp().globalData.mqc);
		},
		async onShow() {			
			//全局只执行一次
			//在这里判断是否处于登录状态
			//如果未登录，则自动跳转对登录页面
			//使用我们封装的小工具判断是否登录
			if (!uni.$u.utils.isLogin()) {
				return;				
			}
			const info = uni.getStorageSync('userinfo');
			this.pic = info.avatar_url;
			this.name = info.name;
			this.email = info.email;
		},
		methods: {
			async logout(){
				let res = await uni.$u.http.post('/api/auth/logout',{},{
					header:{
						Authorization:'bearer ' + access_token
					}
				})
				if(res !== false){
					uni.$u.toast('注销成功');
					uni.clearStorageSync();
					setTimeout(()=>{
						uni.$u.route({
							type:'reLaunch',
							url:'/pages/index/index'
						})
					},1200)
				}				
			}
		}
	}
</script>

<style lang="scss">
	.u-cell{background-color: white;}
	page {
		background-color: #ededed;
	}

	.camera {
		width: 54px;
		height: 44px;

		&:active {
			background-color: #ededed;
		}
	}

	.user-box {
		background-color: #fff;
	}
</style>
